using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;

namespace Kaleida.ServiceMonitor.Model.StructuredSource
{
    internal class ScriptDefinition
    {
        private readonly IList<ScriptDefinition> childGroups = new List<ScriptDefinition>();
        private readonly IList<DirectiveDefinition> directives = new List<DirectiveDefinition>();
        private readonly IList<OperationDefinition> operations = new List<OperationDefinition>();
        private readonly IList<string> comments = new List<string>();

        public ScriptDefinition([NotNull] IList<ScriptDefinition> childGroups)
        {
            if (childGroups == null) throw new ArgumentNullException("childGroups");
            this.childGroups = childGroups;
        }

        public ScriptDefinition([NotNull] IList<DirectiveDefinition> directives, [NotNull] IList<OperationDefinition> operations, [NotNull] IList<string> comments)
        {
            if (directives == null) throw new ArgumentNullException("directives");
            if (operations == null) throw new ArgumentNullException("operations");
            if (comments == null) throw new ArgumentNullException("comments");

            this.directives = directives;
            this.operations = operations;
            this.comments = comments;
        }

        public IList<ScriptDefinition> ChildGroups
        {
            get{return childGroups;}
        }

        public IList<DirectiveDefinition> Directives
        {
            get { return directives; }
        }

        public IList<OperationDefinition> Operations
        {
            get { return operations; }
        }

        public IList<string> Comments
        {
            get { return comments; }
        }

        public override string ToString()
        {
            return string.Join("\r\n", operations.Select(i => i.ToString()));
        }
    }
}